﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace ECCIT.Data
{
    public sealed class DBUtils
    {
        public static readonly string NULL = "NULL";

        public static string SafeToString(object columnValue)
        {
            if (columnValue == null || columnValue == DBNull.Value)
                return NULL;

            return columnValue.ToString();
        }

        public static string SafeToSqlString(object columnValue)
        {
            string s = SafeToString(columnValue);
            if (s == NULL)
                return s;

            return string.Format("'{0}'", s.Replace("'", "''"));
        }
    }
}
